﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VersionComparer.UI.ExtendedTreeView;

namespace VersionComparer
{

    /// <summary>
    /// Form used for searching
    /// </summary>
    public partial class SearchForm : Form
    {

        #region constructors
        public SearchForm():base()
        {
            StartPosition = FormStartPosition.CenterParent;
            InitializeComponent();
            
            MinimizeBox = false;
            MaximizeBox = false;
        }
        
        
        #endregion constructors

        #region properties
        public MultiSelectTreeView TreeView
        {
            get
            {
                return searchControl1.TreeView;
            }
            set
            {
                searchControl1.TreeView = value;
            }
        }
        public string CurrentText
        {
            get
            {
                return searchControl1.CurrentText;
            }
        }
        public string DefaultText
        {
            get
            {
                return searchControl1.DefaultText;
            }
            set
            {
                searchControl1.DefaultText = value;
            }
        }
        #endregion properties

        #region events

        /// <summary>
        /// Handles escape and enter keystrokes
        /// </summary>
        /// <param name="msg">message</param>
        /// <param name="keyData">key</param>
        /// <returns>true if event was handled</returns>
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Escape)
            {
                Hide();
                return true;
            }
            if (keyData == Keys.Enter)
            {
                searchControl1.MoveNext(null);
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        /// <summary>
        /// Initializations
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SearchForm_Load(object sender, EventArgs e)
        {
            
            Icon = Owner.Icon;
            Location = new Point(Owner.Location.X + (Owner.Width - Width) / 2,
                Owner.Location.Y + (Owner.Height - Height) / 2);

        }
        private void btNext_Click(object sender, EventArgs e)
        {
            MoveNext(null);
        }

        private void btPrevious_Click(object sender, EventArgs e)
        {
            MovePrevious(null);
        }
        #endregion properties


        /// <summary>
        /// Searches for the next item in the treeview that matches text
        /// </summary>
        /// <param name="text">text to match</param>
        public void MoveNext(string text)
        {
            searchControl1.MoveNext(text);
        }

        /// <summary>
        /// Searches for the previous item in the treeview that matches text
        /// </summary>
        /// <param name="text">text to match</param>
        public void MovePrevious(string text)
        {
            searchControl1.MovePrevious(text);
        }

      
    }
}
